package com.jinliang.blogweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jinliang.blogweb.entity.Label;
import com.jinliang.blogweb.mapper.LabelMapper;
import com.jinliang.blogweb.service.LabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Service
public class LabelServiceImpl implements LabelService {

    @Autowired
    private LabelMapper labelMapper;
    @Override
    public List<Label> getIsHot() {
        return null;
    }

    @Override
    public Label getLabelByName(String name) {
        QueryWrapper<Label> queryWrapper = new QueryWrapper();
        queryWrapper.lambda()
                .eq(Label::getName, name);
        List<Label> labels = labelMapper.selectList(queryWrapper);
        if (labels.size() == 0) {
            return null;
        }
        return labels.get(0);
    }

    @Override
    public void add(Label label) {
        labelMapper.insert(label);
    }

    @Override
    public void addLinkCount(Label label) {
        label.setLinkCount(label.getLinkCount() + 1);
        labelMapper.updateById(label);
    }
}
